# Maintainer (Arch): Filipe Laíns (FFY00) <lains@archlinux.org>
# Maintainer: Sagar Acharya <sagar@hyperbola.info>

_prj=trellis
pkgname=prj$_prj
pkgver=1.1
pkgrel=1
pkgdesc='Documentation and definitions for the Lattice ECP5 bit-stream format'
arch=('x86_64')
url='https://github.com/YosysHQ/prjtrellis'
license=('ISC' 'Expat')
depends=('boost-libs')
makedepends=('cmake' "$pkgname-db" 'boost' 'python-sphinx' 'python-sphinx_rtd_theme' 'python-recommonmark')
optdepends=('python: Python support')
provides=('libtrellis')
conflicts=('libtrellis')
source=("https://github.com/YosysHQ/prjtrellis/archive/refs/tags/${pkgver}.tar.gz")
sha512sums=('9f53e3eb605deadd635a957e4bdde6ade9f24c0b966b2f9ae62a01f8240508b623c30bf452ac276caffffc46edb00180b866f4bbc3ad58151d6b3c0263ab8f0d')

prepare() {
  cd $pkgname-$pkgver

  sed -i 's|set(LIBDIR "lib64")|set(LIBDIR "lib")|
          s|project(libtrellis)|project(libtrellis VERSION 1.0)|' libtrellis/CMakeLists.txt
}

build() {
  mkdir $pkgname-$pkgver/libtrellis/build
  cd $pkgname-$pkgver/libtrellis/build

  cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=/lib \
    -DCMAKE_BUILD_TYPE=Release

  sed -i '/Boost::python-NOTFOUND/d' CMakeFiles/*.dir/build.make
  sed -i 's|Boost::python-NOTFOUND||g' CMakeFiles/*.dir/link.txt

  make

  cd ../../docs

  make html
}

package() {
  cd $pkgname-$pkgver

  install -dm 755 "$pkgdir"/usr/share/doc/$pkgname
  cp -r --no-preserve=ownership docs/_build/* "$pkgdir"/usr/share/doc/$pkgname/
  rm -rf "$pkgdir"/usr/share/doc/$pkgname/html/.doctrees

  install -Dm644 COPYING -t "$pkgdir"/usr/share/licenses/$pkgname

  cd libtrellis/build

  make DESTDIR="$pkgdir" install

  # The database is provided in a separate package
  rmdir "$pkgdir"/usr/share/$_prj/database
}
